from django.db import models

from lib import BaseModel


# Create your models here.
# 【1】图书表
class Book(BaseModel):
    # 书籍名称
    name = models.CharField(max_length=32, verbose_name="书籍名称")
    # 书籍价格max_digits 数字长度 decimal_places 小数后位数
    price = models.DecimalField(max_digits=5, decimal_places=2, verbose_name="书籍价格")
    # 推荐等级 不推荐 推荐 非常推荐 强烈推荐
    recommend_level = models.IntegerField(choices=(
        (0, "不推荐"),
        (1, "推荐"),
        (2, "非常推荐"),
        (3, "强烈推荐")
    ), verbose_name="推荐等级")
    # 简介 大文本
    desc = models.TextField(verbose_name="书籍简介")
    # 封面图链接
    cover = models.CharField(max_length=255, verbose_name="封面链接")
    # 出版日期
    publish_date = models.DateField(auto_now=True, verbose_name="出版日期")

    # create_time
    # update_time

    # 出版社 一对多
    publish = models.ForeignKey(to="publish.Publish", on_delete=models.CASCADE, null=True)

    # 作者 一对多
    author = models.ManyToManyField(to="author.Author")

    class Meta:
        db_table = "book"


class Adv(BaseModel):
    src = models.CharField(max_length=255, verbose_name="广告图片链接")
    title = models.CharField(max_length=255, verbose_name="广告标题")
    desc = models.TextField(verbose_name="广告详情")
    detail_url = models.CharField(max_length=255, default="https://www.cnblogs.com/dream-ze")

    class Meta:
        db_table = "adv"
